package com.yb.guigu.pick.security.handler;

import com.yb.guigu.pick.core.bean.GuiguResult;
import com.yb.guigu.pick.core.constant.GuiguStatus;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Copyright (C), 2022-2023, 姚兵
 * Author: 32210
 * Date: 2023/6/3 18:24
 * FileName: GuiguPickSecurityExceptionHandler
 * Description:
 */

@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class GuiguPickSecurityExceptionHandler {

    @ExceptionHandler(AccessDeniedException.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public GuiguResult handle(AccessDeniedException accessDeniedException){
        return GuiguResult.error(GuiguStatus.HttpStatus.FORBIDDEN);
    }
}
